﻿using Moq;
using Myotragus.Data.Criteria;
using Myotragus.Data.Tests.Domain;
using NHibernate;
using NHibernate.Criterion;
using NUnit.Framework;

namespace Myotragus.Data.Tests.Tests.Criteria
{
	[TestFixture]
	public class QueryFixtures
	{
		[Test]
		public void Query()
		{
			var criteria = new Mock<ICriteria>();

			criteria.Setup(m => m.SetFirstResult(It.IsAny<int>()));
			criteria.Setup(m => m.SetMaxResults(It.IsAny<int>()));
			criteria.Setup(m => m.AddOrder(It.IsAny<Order>()));
			criteria.Setup(m => m.List()).Returns(new ITestEntity[0]);

			var query = new CriteriaQuery<ITestEntity>(criteria.Object);
			query.Skip(5).Take(100).OrderBy(t => t.IntNullableProperty)
				.ThenBy(t => t.IntProperty).Desc.End();

			criteria.Verify(m => m.SetFirstResult(5));
			criteria.Verify(m => m.SetMaxResults(100));

			var result = query.Execute();
		}
	}
}